"""Commentary.py

Simple log device, instead of using levels of logging, use 
a bitmask to customize what gets kept.

Note: The commentary wil not store anything unless
the flag is set.
"""

from constants import bitmask

CC = bitmask('intro', 'attack', 'brag', 'whine', 'order', 'damage',
    'manager', 'effect',  zero="silent")


class Commentary(object):
    """Commentary(combatmanager, flags)
    flags can use the following values
        CC.SILENT -- no commentary logged
        CC.INTRO -- intro comments are logged
        CC.BRAG -- the winners comments are logged
        CC.WHINE -- the loser's comments are logged
        CC.ORDER -- comments from the orderer are logged
        CC.DAMAGE -- comments from the damager are logged
        CC.MANAGER -- comments from the manager are logged
        CC.EFFECT -- comments from the effects manager
        CC.ALL -- all comments are logged
    """
    def __init__(self, combatmanager = None, flags = CC.ALL):
        self._manager = combatmanager
        self._flags = flags
        self._log = []
        self._last = ''
    
    def comment(self, mark, string):
        if self._flags & mark:
            self._log.append(string)
            self._last = string
            
    def clear(self):
        self._log = []
        self._last = ''
    
    @property
    def last(self):
        return self._last
        
    @property
    def log(self):
        return self._log
    
    @property
    def text(self):
        return "\n".join(self._log)
        
            
if __name__=='__main__':
    c = Commentary(None, CC.INTRO | CC.ATTACK )
    print c
    c.comment(CC.INTRO, "Hello")
    c.comment(CC.ATTACK, "I punch you")
    c.comment(CC.BRAG, 'I kill you')
    print c.log
    print c.text